package com.bosssoft.controller;

import com.bosssoft.baseEnity.SelectItem;
import com.bosssoft.entity.po.FibVoucherDetailsPO;
import com.bosssoft.entity.po.FibVoucherLocationPO;
import com.bosssoft.entity.vo.FibVoucherDetailsVO;
import com.bosssoft.exception.DaoException;
import com.bosssoft.page.PageResult;
import com.bosssoft.response.Result;
import com.bosssoft.service.FibVoucherLocationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Aria
 */
@RequestMapping("/voucherLocation")
@RestController
@Api(tags = "凭证印章位置")
public class FibVoucherLocationController {

    @Autowired
    private FibVoucherLocationService voucherLocationService;

    @ApiOperation(value = "根据编码获取所有可盖章的位置")
    @PostMapping("/getListByCode")
    public Result getListByCode(@RequestBody Integer voucherCode) {
        try {
            List<FibVoucherLocationPO> locationPOList = voucherLocationService.getListByCode(voucherCode);
            return Result.ok().data("list", locationPOList);
        } catch (DaoException e) {
            if (e.getMessage() != null) {
                return Result.error(e.getCode(), e.getMessage());
            }
            return Result.error();
        }
    }

    @ApiOperation(value = "根据凭证编号获取所有可盖章的位置")
    @GetMapping("/getListById")
    public Result getListById(@RequestParam(name = "0") Long voucherId) {
        try {
            List<FibVoucherLocationPO> locationPOList = voucherLocationService.getListById(voucherId);
            SelectItem[] selectItems = new SelectItem[locationPOList.size()];
            for (int i = 0; i < locationPOList.size(); i++) {
                selectItems[i] = new SelectItem("从左往右数第" + (i + 1) + "个位置", locationPOList.get(i).getVoucherLocationId().toString());
            }
            return Result.ok().data("map", selectItems);
        } catch (DaoException e) {
            if (e.getMessage() != null) {
                return Result.error(e.getCode(), e.getMessage());
            }
            return Result.error();
        }
    }
}
